package com.springapp.mvc.dm;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * Created by shangdong on 17/4/9.
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Product {
    private String productUrl;
    private int buyCount;

    public static Product parseProduct(String product){
        String[] split = product.split(",");
        int i = parseInt(split[1]);
        return new Product(split[0],i);
    }

    public static List<Product> getAllProduct(){
        return Lists.newArrayList(
//                new Product("https://www.dm.de/aptamil-kindermilch-ab-2-jahren-p4008976022312.html",35),
//                new Product("https://www.dm.de/aptamil-profutura-anfangsmilch-pre-von-geburt-an-p4008976022923.html",28),
//                new Product("https://www.dm.de/aptamil-profutura-folgemilch-2-nach-dem-6-monat-p4008976022916.html",28),
//                new Product("https://www.dm.de/aptamil-profutura-anfangsmilch-1-p4008976022909.html",28),
                new Product("https://www.dm.de/babylove-folgemilch-2-nach-dem-6-monat-p4010355244406.html", 2)
//                new Product("https://www.dm.de/aptamil-kindermilch-ab-1-jahr-p4008976022305.html",1)

        );
    }

    private static int parseInt(String count) {
        try {
            return Integer.parseInt(count);
        }catch (Exception e){
            System.out.println("count isn't number! count = "+ count);
            return 0;
        }
    }
}